package com.ninth.element.generated.number.generate.common.pojo.enums;

import org.springframework.util.StringUtils;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * 重置类型
 *
 * @author LiYUJi
 **/
public enum ResetTypeEnum {

    /**
     * 每毫秒 -- 仅redis支持
     **/
    MILLISECOND("MILLISECOND", "每毫秒"),
    /**
     * 每秒  -- 仅redis支持
     **/
    SECOND("SECOND", "每秒"),
    /**
     * 每天
     **/
    DAY("DAY", "每天"),
    /**
     * 每月
     **/
    MONTH("MONTH", "每月"),
    /**
     * 每年
     **/
    YEAR("YEAR", "每年");


    ResetTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }


    ResetTypeEnum() {
        this.code = "DAY";
        this.desc = "每天";
    }

    /**
     * 编码
     */
    private String code;

    /**
     * 描述
     */
    private String desc;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static ResetTypeEnum codeOf(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        Optional<ResetTypeEnum> codeEnum = Stream.of(ResetTypeEnum.values()).filter(sst -> code.equals(sst.getCode())).findAny();
        return codeEnum.orElse(null);
    }
}
